package com.company;

import java.util.concurrent.*;


public class TestThreadPool {
    public final  static int coreNum = Runtime.getRuntime().availableProcessors();
    public static void testThreadPool(){
        System.out.println("thread num :"+coreNum);

        Counter count = new MongoCounter();
        ScheduledExecutorService pool = Executors.newScheduledThreadPool(coreNum);
        ScheduledExecutorService sch = Executors.newScheduledThreadPool(1);
        sch.scheduleWithFixedDelay(()->{
                    System.out.println(count.get());
        },0,100, TimeUnit.MILLISECONDS);

        pool.scheduleWithFixedDelay (()->{
            count.add();
        },0,100,TimeUnit.MILLISECONDS);

        pool.scheduleWithFixedDelay (()->{
            count.dec();
        },0,100,TimeUnit.MILLISECONDS);

    }

}
